<?php

namespace App\Admin\Controllers;

use App\Admin\Repositories\ErrorPath;
use Dcat\Admin\Form;
use Dcat\Admin\Grid;
use Dcat\Admin\Show;
use Dcat\Admin\Http\Controllers\AdminController;

class ErrorPathController extends AdminController
{
    /**
     * Make a grid builder.
     *
     * @return Grid
     */
    protected function grid()
    {
        return Grid::make(new ErrorPath(), function (Grid $grid) {
            $grid->model()->orderBy('created_at','desc');
            $grid->column('domain')->sortable()->filter();
            $grid->column('path');
            $grid->column('ip')->filter();
            $grid->column('type')->using([1 => '图片', 2 => '视频'])->label([
                'default' => 'primary', // 设置默认颜色，不设置则默认为 default
                1 => 'primary',
                2 => 'danger',
            ]);
            $grid->column('ua')->width('100px');
            $grid->column('created_at')->sortable()->filter();
        

            $grid->disableCreateButton();
            $grid->disableActions();
            $grid->disableFilterButton();
            $grid->quickSearch(['domain', 'path', 'ip']);
            
        });
    }

    /**
     * Make a show builder.
     *
     * @param mixed $id
     *
     * @return Show
     */
    protected function detail($id)
    {
        return Show::make($id, new ErrorPath(), function (Show $show) {
            $show->field('id');
            $show->field('domain');
            $show->field('path');
            $show->field('ip');
            $show->field('created_at');
            $show->field('updated_at');
        });
    }

    /**
     * Make a form builder.
     *
     * @return Form
     */
    protected function form()
    {
        return Form::make(new ErrorPath(), function (Form $form) {
            $form->display('id');
            $form->text('domain');
            $form->text('path');
            $form->text('ip');
            $form->radio('type')->default(1);
        
            $form->display('created_at');
            $form->display('updated_at');
        });
    }
}
